
#ifndef LOD_VECTOR3_H
#define LOD_VECTOR3_H

#include <cmath>

template<class co_type>
class vector3
{
    public:
    co_type x;
    co_type y;
    co_type z;


    vector3(co_type X, co_type Y, co_type Z)
     : x(X), y(Y), z(Z)
    {
    }

    vector3(const co_type* coordinates)
    {
        x = coordinates[0];
        y = coordinates[1];
        z = coordinates[2];
    }

    vector3()
    {
    }

    //! Normalize the vector (rescale it to the length of 1 unit)
    void normalize()
    {
        co_type length = norm();
        if(length!=(co_type)0) {
            x /= length;
            y /= length;
            z /= length;
        }
    }

    //! Returns the norm (~ length) of the vector
    co_type norm()
    {
        return std::sqrt(x*x + y*y + z*z);
    }


    /*!
     * \param n A vector to compare this vector with */
    bool operator== (const vector3 & n) const
    {
        //todo: the compare method below depends purely on the ~float comparison,
        // which might be not what we want; 
        // maybe a comparison with given epsilon accuracy would be more useful? 
        return (x == n.x &&
                y == n.y &&
                z == n.z);
    }
};

#endif // LOD_VECTOR3_H
